﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using QASampling.BusinessObject;

namespace QASampling.UI
{
    public partial class frmLogin : BaseFormWithHeader
    {
        public frmLogin()
        {
            InitializeComponent();
            
        }

        private void btnMasuk_Click(object sender, EventArgs e)
        {
            try
            {
                this.Cursor = Cursors.WaitCursor;

                string username = txtUsername.Text;
                string password = txtPassword.Text;

                //if added by Vincent for validation login to qa sampling not for admin and supervisor 20130201
                if (QAController.Login(username, password))
                {
                    if (QAController.IsAdmin(username) || QAController.IsSupervisor(username))
                    {
                        string msg = "Login QA Sampling hanya untuk petugas. Jika Anda Admin atau Supervisor harap gunakan QA Admin";
                        MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        QAController.Username = username;
                        QAController.UbahStatusLoginPetugas(1);
                        this.DialogResult = System.Windows.Forms.DialogResult.OK;
                    }
                }
                else
                {
                    string msg = "Username atau password salah / User sedang login " + Environment.NewLine + "Harap hubungi Supervisor ";
                    MessageBox.Show(msg, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, this.Text, MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                this.Cursor = Cursors.Default;
            }
        }
    }
}
